<template>
  <div>
    <van-nav-bar title="账号登陆" left-arrow/>
    <van-form @submit="onSubmit">
      <van-field
        v-model="userList.username"
        name="用户名"
        placeholder="用户名"
        style="height:70px;"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="userList.password"
        type="password"
        name="密码"
        placeholder="密码"
        style="height:70px;"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
        round block type="info"
         native-type="submit"
        square color="#87d2b9"
          >提交</van-button
        >
      </div>
    </van-form>
    <div class="div">还没有账号？去注册～</div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { Toast } from 'vant'
export default {
  data () {
    return {
      userList: {
        username: 'hzhmqd',
        password: '123456'
      }
    }
  },
  methods: {
    ...mapActions(['getUserList']),
    async onSubmit () {
      try {
        await this.getUserList(this.userList)
        this.$router.push('/home')
        Toast('登陆成功！')
      } catch (err) {
        console.log(err)
        Toast('登陆失败！')
      }
    }

  }
}
</script>

<style lang="less" scoped>
/deep/.van-nav-bar__content {
  background-color: #6dd4b8;
  .van-nav-bar__title {
    color: #fff;
  }
}
.van-field{
  line-height: 70px;
}
.div{
  font-size: 14px;
  text-align: center;
  margin-top: 20px;
  color: #666666;
}
</style>
